package com.mf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mf.entity.bo.UserBo;
import com.mf.entity.req.search.UserSearchReq;
import com.mf.mapper.UserMapper;
import com.mf.service.IUserService;
import io.micrometer.common.util.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;

/**
 * 服务实现类
 *
 * @author mf
 * @since 2025-03-08
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, UserBo> implements IUserService {
    /**
     * 查询用户
     */
    @Override
    public Page<UserBo> findPageList(UserSearchReq userSearchReq) {
        final Page<UserBo> page = new Page<>(userSearchReq.getPageNum(), userSearchReq.getPageSize());
        final LambdaQueryWrapper<UserBo> wrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotBlank(userSearchReq.getKey())) {
            wrapper.like(UserBo::getUName, userSearchReq.getKey())
                    .or().like(UserBo::getEmail, userSearchReq.getKey())
            ;
        }
        return this.baseMapper.selectPage(page, wrapper);
    }
}
